package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DA_FU_WENG_USE_IETM, desc = "大富翁使用道具")
public class DaFuWengUseGoodCmd extends AbstractCommand {
    private int goodId;
    private int count;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.UseDFWGoodReqMsg msg = MonopolyProto.UseDFWGoodReqMsg.parseFrom(packet.getBytes());
        goodId = msg.getGoodId();
        count = msg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        MonopolyProto.UseDFWGoodRespMsg.Builder respMsg = MonopolyProto.UseDFWGoodRespMsg.newBuilder();

        ret = DaFuWengMgr.checkGroup(player.getUserId());
        if (ret != 0) {
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_IETM, respMsg);
            return;
        }

        DaFuWengMgr.useGood(goodId, count, player, respMsg);
        player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_IETM, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
